package com.ylxin.smartplatform.controller;

import com.ylxin.smartplatform.dto.R;
import com.ylxin.smartplatform.pojo.SysDevice;
import com.ylxin.smartplatform.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 29048
 * @version V1.0
 * @Project bk2205
 * @Package com.ylxin.smartplatform.controller
 * @Description: Create by 杨立新 @Date 2022/9/15 22:43
 */
@RestController
@RequestMapping("/devices")
public class DeviceController {
    private DeviceService deviceService;

    @Autowired
    public void setDeviceService(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    public R addDevice(@RequestBody @Validated SysDevice sysDevice){
        deviceService.addDevice(sysDevice);
        return R.OK();
    }

    @PostMapping("/command/{deviceId}/{cmmand}")
    public R sendCommand(@PathVariable("deviceId") String deviceId, @PathVariable("command") String command){
        deviceService.sendCommand(deviceId,command);
        return R.OK();
    }
}
